home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / regenprops.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-11  |  6.4 KB  |  260 lines

  1. // RegenProps.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "RegenWizard.h"
  6. #include "RegenProps.h"
  7.  
  8. #include "RegenWizardAW.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CRegenProps dialog
  18.  
  19.  
  20. CRegenProps::CRegenProps(CRegenWizardAppWiz *pMain, CWnd* pParent /*=NULL*/)
  21.     : CAppWizStepDlg(CRegenProps::IDD),
  22.     m_pclsMain(pMain)
  23. {
  24.     //{{AFX_DATA_INIT(CRegenProps)
  25.     m_strName = _T("");
  26.     m_strValue = _T("");
  27.     m_iPropType = 0;
  28.     //}}AFX_DATA_INIT
  29.  
  30.     m_iPropCount = 0;
  31.  
  32.     m_pclsMain->m_Dictionary[_T("PropertiesCount")]                        = _T("0");
  33.     m_pclsMain->m_Dictionary[_T("RegenPropertiesGenerated")]            = _T("");
  34.     m_pclsMain->m_Dictionary[_T("RegenPropertiesStringTable")]            = _T("");
  35.     m_pclsMain->m_Dictionary[_T("RegenPropertiesValuesStringTable")]    = _T("");
  36.     m_pclsMain->m_Dictionary[_T("RegenPropertiesIDS")]                    = _T("");
  37. }
  38.  
  39.  
  40. void CRegenProps::DoDataExchange(CDataExchange* pDX)
  41. {
  42.     CDialog::DoDataExchange(pDX);
  43.     //{{AFX_DATA_MAP(CRegenProps)
  44.     DDX_Control(pDX, IDC_PROP_LIST, m_listAll);
  45.     DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
  46.     DDX_Text(pDX, IDC_EDIT_VALUE, m_strValue);
  47.     DDX_CBIndex(pDX, IDC_COMBO_TYPE, m_iPropType);
  48.     //}}AFX_DATA_MAP
  49. }
  50.  
  51.  
  52. BEGIN_MESSAGE_MAP(CRegenProps, CAppWizStepDlg)
  53.     //{{AFX_MSG_MAP(CRegenProps)
  54.     ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
  55.     ON_BN_CLICKED(IDC_BUTTON_REMOVE, OnButtonRemove)
  56.     ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit)
  57.     //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CRegenProps message handlers
  62. const char* strTypes[14] =
  63. {
  64.     "byte",
  65.     "char",
  66.     "unsigned short",
  67.     "short",
  68.     "unsigned long",
  69.     "long",
  70.     "unsigned int",
  71.     "int",
  72.     "float",
  73.     "double",
  74.     "BOOL",
  75.     "BSTR",
  76.     "SCODE",
  77.     "Cyrrency"
  78. };
  79.  
  80. const char* strVarSizes[14] =
  81. {
  82.     "UI1",
  83.     "I1",
  84.     "UI2",
  85.     "I2",
  86.     "UI4",
  87.     "I4",
  88.     "UINT",
  89.     "INT",
  90.     "R4",
  91.     "R8",
  92.     "BOOL",
  93.     "BSTR",
  94.     "ERROR",
  95.     "CY"
  96. };
  97.  
  98. const char* strVarFields[14] = 
  99. {
  100.     ".bVal",
  101.     ".cVal",
  102.     ".uiVal",
  103.     ".iVal",
  104.     ".ulVal",
  105.     ".lVal",
  106.     ".uintVal",
  107.     ".intVal",
  108.     ".fltVal",
  109.     ".dblVal",
  110.     ".boolVal",
  111.     ".bstrVal",
  112.     ".scode",
  113.     ".cyVal"
  114. };
  115.  
  116. void CRegenProps::OnButtonAdd() 
  117. {
  118.     // TODO: Add your control notification handler code here
  119.     UpdateData();
  120.  
  121.     if (!m_strName.GetLength()) return;
  122.     
  123.     m_strPropNames    [m_iPropCount] = m_strName;
  124.     m_strPropValues [m_iPropCount] = m_strValue;
  125.     m_PropTypes        [m_iPropCount] = m_iPropType;
  126.  
  127.     m_iPropCount ++;
  128.  
  129.     m_listAll.AddString ((CString)strTypes[m_iPropType]+"   "+m_strName+" = "+m_strValue);
  130.  
  131.     GenSrcCode();
  132. }
  133.  
  134. void CRegenProps::OnButtonRemove() 
  135. {
  136.     // TODO: Add your control notification handler code here
  137.     if (!m_iPropCount) return;
  138.  
  139.     int iCurSel = m_listAll.GetCurSel();
  140.  
  141.     if (iCurSel != LB_ERR)
  142.         m_listAll.DeleteString(iCurSel);
  143.  
  144.     for (int i = iCurSel; i < --m_iPropCount; i++)
  145.     {
  146.         m_strPropNames    [i] = m_strPropNames    [i + 1];
  147.         m_strPropValues    [i] = m_strPropValues    [i + 1];
  148.         m_PropTypes        [i] = m_PropTypes        [i + 1];
  149.     }
  150.     
  151.     if (iCurSel == m_iPropCount) iCurSel--;
  152.     if (iCurSel >= 0) m_listAll.SetCurSel(iCurSel);
  153.  
  154.     GenSrcCode();
  155. }
  156.  
  157. CString AddString(CString strBeg, CString strSuffix, CString strRight)
  158. {
  159.     CString    strResult = "\t\t"+strBeg+strSuffix;
  160.     
  161.      if (strSuffix.GetLength() == 0) strResult += "\t\t\t= ";
  162. else if (strSuffix.GetLength() <= 4) strResult += "\t\t= ";
  163. else strResult += "\t= ";
  164.     strResult += strRight+";\n";
  165.  
  166.     return strResult;
  167. };
  168.  
  169. void CRegenProps::GenSrcCode() 
  170. {
  171.     // TODO: Add your control notification handler code here
  172.     CString strResult                = "";
  173.     CString strStringTableNames        = "";
  174.     CString strStringTableValues    = "";
  175.     CString strResourceIDS            = "";
  176.     CString strIndex, strCount;
  177.     int        j                        = 0;
  178.     
  179.     strCount.Format("%i", m_iPropCount);
  180.  
  181.     for (int i = 0; i < m_iPropCount; i++)
  182.     {
  183.         strIndex.Format("%i", i+1);
  184.  
  185.         strResult += AddString("bstrNames\t[lTmpIndex]",    "",        (CString)"MakeBSTR(IDS_REGENPROP_" + strIndex + ")");
  186.         strResult += AddString("lTypes\t\t[lTmpIndex]",        "",        (CString)"VT_" + strVarSizes[m_PropTypes[i]]);
  187.         strResult += AddString("lIDs\t\t[lTmpIndex]",        "",        "lTmpIndex+1");
  188.         strResult += AddString("varDefaults\t[lTmpIndex]",  ".vt",    (CString)"VT_" + strVarSizes[m_PropTypes[i]]);
  189.  
  190.         strStringTableNames +=    "\tIDS_REGENPROP_" + strIndex + "\t\t\"" + 
  191.                                 m_strPropNames[i] + "\"\n";
  192.  
  193.         if (m_PropTypes[i] == 11) 
  194.         {
  195.             j++;
  196.             strIndex.Format("%i", j);
  197.  
  198.             strResult += AddString(    "varDefaults\t[lTmpIndex]", 
  199.                                     strVarFields[m_PropTypes[i]], 
  200.                                     (CString)"MakeBSTR(IDS_REGENPROP_BSTRVALUE_" + strIndex + ")");
  201.             strStringTableValues +=    "\tIDS_REGENPROP_BSTRVALUE_" + 
  202.                                     strIndex+"\t\t\"" + 
  203.                                     m_strPropValues[i] + "\"\n";
  204.         }
  205.         else
  206.             strResult += AddString("varDefaults\t[lTmpIndex]", strVarFields[m_PropTypes[i]], m_strPropValues[i]);
  207.  
  208.         strResult += "\t\tlTmpIndex++;\n\n";
  209.     };
  210.  
  211.     if (m_iPropCount)
  212.         strStringTableNames        =    "STRINGTABLE\tDISCARDABLE\nBEGIN\n" +
  213.                                     strStringTableNames +
  214.                                     "END\n";
  215.     if (j)
  216.         strStringTableValues    =    "STRINGTABLE\tDISCARDABLE\nBEGIN\n" +
  217.                                     strStringTableValues +
  218.                                     "END\n";
  219.  
  220.     for (i = 0; i < m_iPropCount; i++)
  221.     {
  222.         strIndex.Format("%i", i + 1);
  223.         strResourceIDS += "#define\tIDS_REGENPROP_" + strIndex + "\t\t\t\t\t";
  224.         strIndex.Format("%i\n", 200+i+1);
  225.         strResourceIDS += strIndex;
  226.     };
  227.     
  228.     for (i = 0; i < j; i++)
  229.     {
  230.         strIndex.Format("%i", i + 1);
  231.         strResourceIDS += "#define\tIDS_REGENPROP_BSTRVALUE_" + strIndex + "\t\t";
  232.         strIndex.Format("%i\n", 200 + m_iPropCount + 1 + i);
  233.         strResourceIDS += strIndex;
  234.     };
  235.  
  236.     m_pclsMain->m_Dictionary [_T("PropertiesCount")]            = strCount;
  237.     m_pclsMain->m_Dictionary [_T("RegenPropertiesGenerated")]    = strResult;
  238.  
  239.     m_pclsMain->m_Dictionary [_T("RegenPropertiesStringTable")]            = strStringTableNames;
  240.     m_pclsMain->m_Dictionary [_T("RegenPropertiesValuesStringTable")]    = strStringTableValues;
  241.     m_pclsMain->m_Dictionary [_T("RegenPropertiesIDS")]                    = strResourceIDS;
  242. }
  243.  
  244. void CRegenProps::OnButtonEdit() 
  245. {
  246.     // TODO: Add your control notification handler code here
  247.     if (!m_iPropCount) return;    
  248.  
  249.     int        iCurSel    = m_listAll.GetCurSel();
  250.  
  251.     if (iCurSel == LB_ERR) return;
  252.  
  253.     m_strName    = m_strPropNames    [iCurSel];
  254.     m_strValue    = m_strPropValues    [iCurSel];
  255.     m_iPropType = m_PropTypes        [iCurSel];
  256.  
  257.     UpdateData(false);
  258.     OnButtonRemove();
  259. }
  260.